package org.dream.imitate;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import org.dream.domain.Account;
import org.dream.domain.DealPlan;
import org.dream.util.DoubleUtil;

/**
 *止损交易测试  
 * @author 关攀攀
 */
public class ZhiZunJYPanel extends JPanel {
	private JComboBox box;
	private JTable table;
	private DefaultTableModel tableModel;
	private String[] columnNames = { "序号","时间", "股票代码", "买卖类型", "买入原因", "成交数量", "成交金额","持股数", "余额" };
	private Object[][] data;
	private ZhiZunService zhiZunService = new ZhiZunService();

	public ZhiZunJYPanel() {
		super(new BorderLayout());
		// 添加股票分类Box
		addStockKindBox();

		// 初始化股票数据表格
		addStockDataTable();

	}

	/**
	 * 添加股票分类Box
	 */
	private void addStockKindBox() {
		box.setBounds(210, 10, 50, 20);
		box.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			//	refreshStockDataTable();

			}

		});
		this.add(box, BorderLayout.NORTH);
	}

	/**
	 * 初始化股票数据表格
	 */
	private void addStockDataTable() {
		DealPlan plan=new DealPlan();
		plan.setMaiChuDay(10);
		plan.setMaiChuZf(-10);
		plan.setMaiRuDay(10);
		plan.setMaiRuZf(10);
		Account account=zhiZunService.testZhiSun("000060", plan);
		data=new Object[account.getJiaoYis().size()][9];
		for (int i = 0; i < account.getJiaoYis().size(); i++) {
			data[i][0] = "" + (i + 1);
			data[i][1] = account.getJiaoYis().get(i).getDate();
			data[i][2] = account.getJiaoYis().get(i).getStockCode();
			data[i][3] = account.getJiaoYis().get(i).getKindView();
			data[i][4] = DoubleUtil.scale2(account.getJiaoYis().get(i).getCause());
			data[i][5] = account.getJiaoYis().get(i).getNum();
			data[i][6] = account.getJiaoYis().get(i).getMoney();
			data[i][7] = account.getJiaoYis().get(i).haveNum;
			data[i][8] = account.getJiaoYis().get(i).getYuer();
		}
		table = new JTable(data, columnNames);
		add(new JScrollPane(table), BorderLayout.CENTER);
	}

	/**
	 * 更新数据表格数据
	 *//*
	private void refreshStockDataTable() {
		data = zhiZunService.getTableStock((StockKind) box.getSelectedItem(), null, null);
		tableModel = new DefaultTableModel(data, columnNames);
		table.setModel(tableModel);
		table.updateUI();
	}*/
}
